///////////////////////////////////////////////////
// Election Administration Polarization
// Plot RD Estimates Across States
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"


////
// Plotting the effect on presidential vote share over time
////

* Bring in the presidential election analysis data
use "$path/analysis_data/rd_election_analysis_data.dta", clear
keep if office=="pres"

* Run separate regressions by state
gen b = .
gen u = .
gen l = .
gen s = ""
local i = 1
levelsof state, local(states)
foreach s in `states' {
	count if state=="`s'"
	if r(N)<50 continue
	cap rdrobust r_oos_state_year_vs_dem rv if state=="`s'", vce(cluster election_id)
	if _rc==0 {
		replace b = e(tau_cl) if _n==`i'
		replace u = e(tau_cl) - 1.96*e(se_tau_cl) if _n==`i'
		replace l = e(tau_cl) + 1.96*e(se_tau_cl) if _n==`i'
		replace s = "`s'" if _n==`i'
		local i = `i' + 1
	}
}

* Plot the estimates over time
egen s_num = group(s)
replace s_num = -s_num
label define s_lab -1 "Alabama" -2 "Colorado" -3 "Florida" -4 "Iowa" -5 "Illinois" -6 "Indiana" -7 "Kentucky" -8 "Texas" 
label values s_num s_lab 
twoway (rcap l u s_num, horizontal lc(gs10) mc(gs10)) ///
	(scatter s_num b, mc(gs4)), ///
	xli(0, lp(dash) lc(gs10)) ///
	ysc(r(-8.5 -0.5)) ylab(-8(1)-1, valuelabel angle(horizontal) notick nogrid) ///
	xsc(r(-0.1 0.1)) xlab(-0.08(0.04)0.08) ///
	yti("") xti("Effect on Dem Pres Vote") ///
	legend(off) scheme(s2color) graphregion(color("white"))
graph export "$path/output/rd_dem_vs_by_state.pdf", replace

